package com.ljf.dao.impl;

import java.util.List;
import java.util.Properties;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ljf.dao.IUserDao;
import com.ljf.entity.User;

public class UserDaoImpl extends HibernateDaoSupport implements IUserDao{

	@SuppressWarnings("unchecked")
	@Override
	public List<User> findAll() {
		return getHibernateTemplate().loadAll(User.class);
	}

	@Override
	public User find(int id) {
		return (User) getHibernateTemplate().get(User.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<User> find(Properties prop) {
		return getHibernateTemplate().findByCriteria(DetachedCriteria.forClass(User.class).add(Expression.allEq(prop)));
		
	}

	@Override
	public void add(User u) {
		getHibernateTemplate().save(u);
	}

	@Override
	public void chage(User u) {
		getHibernateTemplate().update(u);
		
	}

	@Override
	public void delete(User u) {
		getHibernateTemplate().delete(u);
		
	}

	
}
